#include <Master.hpp>
#include <Sieve.hpp>
#include <mpi.h>
#include <fstream>

int main (int argc, char* argv[]) {
	MPI::Init(argc, argv);

	int exchangeTime;
	sscanf(argv[2], "%d", &exchangeTime);

	int pid 	  = MPI::COMM_WORLD.Get_rank();
	int processes = MPI::COMM_WORLD.Get_size();

	Runnable * runnable;

	std::fstream file;

	if (!pid) {
		file.open(argv[1], std::fstream::in);
		runnable = new Master(file, processes, exchangeTime);
	} else {
		runnable = new Sieve(pid, processes, exchangeTime);
	}

	runnable->run();

	file.close();
	delete runnable;

	return 0;
}
